import store from '@/store'
import client from 'webpack-theme-color-replacer/client'
import forElementUI from 'webpack-theme-color-replacer/forElementUI'

export function initThemeColor(theme) {
  if (theme) {
    changeThemeColor(theme)
  }
}

export function changeThemeColor(newTheme) {
  let options = {
    newColors: [...forElementUI.getElementUISeries(newTheme)]
  }
  return client.changer.changeColor(options).then(item => {
    localStorage.setItem('COLOR_THEME', newTheme)
    store.commit('system/SET_THEME', newTheme)
  })
}
